package ao

import (
	"context"
	pb "gitee.com/micro-services/protocol/area/server"
	"micro.area.server/impl"
	"micro.area.server/plugins"
)

type Area struct{}

func (ar *Area) AreaList(ctx context.Context, r *pb.AreaListReq, w *pb.AreaListRsp) error {
	list, err := impl.AreaList(ctx)
	if err != nil {
		return err
	}

	w.AreaList = list
	plugins.DealWithTracer(ctx, "go.micro.area.server.AreaList", r, w)
	return nil
}

func (ar *Area) CreateCircle(ctx context.Context, r *pb.CreateCircleReq, w *pb.CreateCircleRsp) error {
	rsp, err := impl.CreateCircle(ctx, r)
	if err != nil {
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg
	return nil
}

func (ar *Area) DeleteCircle(ctx context.Context, r *pb.DeleteCircleReq, w *pb.DeleteCircleRsp) error {
	rsp, err := impl.DeleteCircle(ctx, r)
	if err != nil {
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg
	return nil
}

func (ar *Area) BatchCircleInfo(ctx context.Context, r *pb.BatchCircleInfoReq, w *pb.BatchCircleInfoRsp) error {
	infos, err := impl.BatchCircleInfo(ctx, r)
	if err != nil {
		return err
	}

	w.BusinessCircleInfo = infos
	return nil
}

func (ar *Area) SearchCircle(ctx context.Context, r *pb.SearchCircleReq, w *pb.SearchCircleRsp) error {
	list, count, err := impl.SearchCircle(ctx, r)
	if err != nil {
		return err
	}

	w.BusinessCircleInfo = list
	w.Count = count
	return nil
}
